package ro.ubbcluj.cs.damate.services;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import ro.ubbcluj.cs.damate.persistence.entities.Task;
import ro.ubbcluj.cs.damate.persistence.entities.User;
import ro.ubbcluj.cs.damate.persistence.repository.TaskRepository;

import java.util.List;

/**
 * @author Lóránd Fazakas (lorand)
 *         Date: 5/10/12
 *         Time: 9:49 PM
 */
@Service
public class TaskService {

    @Autowired
    private TaskRepository taskRepository;

    @Transactional
    public void create(Task transientTask) {
        taskRepository.save(transientTask);
    }

    @Transactional
    public void update(Task persistentTask) {
        taskRepository.save(persistentTask);
    }

    @Transactional
    public void delete(Task persistentTask) {
        taskRepository.delete(persistentTask);
    }

    public List<Task> findAll() {
        return taskRepository.findAll();
    }

    public List<Task> findByUser(User user) {
        return taskRepository.findByUser(user);
    }

    public Task loadTaskWithRelatedObjects(Task task) {
        return taskRepository.loadTaskWithRelatedObjects(task.getTaskId());
    }
}
